<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/WEB-INF/faces/template.xhtml">
        <ui:define name="title">
            <h:outputText value="Shipping Invoice"></h:outputText>
        </ui:define>
        <ui:define name="content">
            <h:panelGroup id="messagePanel" layout="block">
                <p:growl sticky="true" globalOnly="false"/>
            </h:panelGroup>
            <h:form>
                <p:panel id="entryPanel" header="New Shipping Invoice" style="border: none;" >
                    <h:panelGrid columns="2">
                        <h:panelGrid  columns="3">

                            <h:outputLabel value="Consignor" for="consignor"  style="font-weight: bold;"/>
                            <h:selectOneMenu id="consignor" value="#{invoiceBean.selected.consignor}">
                                <f:selectItems value="#{invoiceBean.customers}"/>
                            </h:selectOneMenu>
                            <p:message for="consignor" />

                            <h:outputLabel value="Consignee" for="consignee"  style="font-weight: bold;" />
                            <h:selectOneMenu id="consignee" value="#{invoiceBean.selected.consignee}" >
                                <f:selectItems value="#{invoiceBean.customers}"/>
                            </h:selectOneMenu>
                            <p:message for="consignee" />

                            <h:outputLabel value="From" for="from"  style="font-weight: bold;"/>
                            <h:inputText id="from" value="#{invoiceBean.selected.shippingFrom}" requiredMessage="* Required" required="true"/>
                            <p:message for="from" />

                            <h:outputLabel value="To" for="to"  style="font-weight: bold;"/>
                            <h:inputText id="to" value="#{invoiceBean.selected.shippingTo}" required="true" requiredMessage="* Required"/>
                            <p:message for="to" />


                        </h:panelGrid>

                        <h:panelGrid columns="3" style="padding-left: 300px;">
                            <h:outputLabel value="To Pay" for="toPay"  style="font-weight: bold;"/>
                            <h:selectBooleanCheckbox  id="toPay" value="#{invoiceBean.selected.toPay}"/>
                            <p:message for="toPay" />

                            <h:outputLabel value="Extra Charge" for="charge"  style="font-weight: bold;"/>
                            <h:inputText  id="charge" size="10"  value="#{invoiceBean.selected.extraCharge}"  required="true" validatorMessage="&nbsp;*" requiredMessage="&nbsp;*"  style="text-align: right">
                                <f:convertNumber currencySymbol="" type="currency"/>
                                <f:validateDoubleRange minimum="0.00"/>
                            </h:inputText>
                            <h:message for="charge" style="font-weight: bold;color: red"/>

                            <h:outputLabel value="Discount" for="discount"  style="font-weight: bold;"/>
                            <h:inputText     id="discount" size="10" value="#{invoiceBean.selected.discount}"  required="true" validatorMessage="&nbsp;*" requiredMessage="&nbsp;*"  style="text-align: right">
                                <f:convertNumber currencySymbol="" type="currency"/>
                                <f:validateDoubleRange minimum="0.00"/>
                            </h:inputText>
                            <h:message for="discount" style="font-weight: bold;color: red"/>

                            <h:outputLabel value="Paid Amount" for="paid"  style="font-weight: bold;"/>
                            <h:inputText id="paid" size="10" value="#{invoiceBean.selected.paidAmount}" required="true" validatorMessage="&nbsp;*" requiredMessage="&nbsp;*"  style="text-align: right" >
                                <f:convertNumber currencySymbol="" type="currency"/>
                                <f:validateDoubleRange minimum="0.00"/>
                            </h:inputText>
                            <h:message for="paid" style="font-weight: bold;color: red"/>

                        </h:panelGrid>
                    </h:panelGrid>

                    <p:dataTable id="itemTable" value="#{invoiceBean.model}" style="width: 800px;" dblClickSelect="true"  update="itemTable" var="item" rowIndexVar="index" selection="#{invoiceBean.selectedInvoiceItem}" selectionMode="single"  >
                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="SN"/>
                            </f:facet>
                            <h:outputText value="#{index+1}" />
                        </p:column>

                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="Said To Contain"/>
                            </f:facet>
                            <h:outputText value="#{item.itemDiscription}" rendered="#{item != invoiceBean.selectedInvoiceItem}"/>
                            <h:inputText id="desc" size="33" value="#{item.itemDiscription}" required="true" requiredMessage="&nbsp;*" rendered="#{item == invoiceBean.selectedInvoiceItem}" />
                            <h:message for="desc" style="font-weight: bold;color: red"/>
                        </p:column>

                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="No. Of Packages"/>
                            </f:facet>
                            <h:outputText value="#{item.packageCount}" rendered="#{item != invoiceBean.selectedInvoiceItem}"/>
                            <h:inputText id="pkgCount" size="8"  value="#{item.packageCount}"  validatorMessage="&nbsp;*" required="true" requiredMessage="&nbsp;" rendered="#{item == invoiceBean.selectedInvoiceItem}" style="text-align: right;">
                                <f:validateLongRange minimum="1"  />
                            </h:inputText>
                            <h:message for="pkgCount" style="font-weight: bold;color: red"/>
                        </p:column>


                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Actual Wt."/>
                            </f:facet>

                            <h:outputText value="#{item.actualWeight}" rendered="#{item != invoiceBean.selectedInvoiceItem}"/>
                            <h:inputText  id="actWt" size="8"  value="#{item.actualWeight}" required="true" validatorMessage="&nbsp;*" requiredMessage="&nbsp;*" rendered="#{item == invoiceBean.selectedInvoiceItem}" style="text-align: right;">
                                <f:validateDoubleRange minimum="0.09"/>
                            </h:inputText>
                            <h:message for="actWt" style="font-weight: bold;color: red"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Charged Wt."/>
                            </f:facet>
                            <h:outputText value="#{item.chargedWeight}" rendered="#{item != invoiceBean.selectedInvoiceItem}"/>
                            <h:inputText id="chgWt" size="8"  value="#{item.chargedWeight}" required="true" validatorMessage="&nbsp;*" requiredMessage="&nbsp;*" rendered="#{item == invoiceBean.selectedInvoiceItem}" style="text-align: right;">
                                <f:validateDoubleRange minimum="0.09"/>
                            </h:inputText>
                            <h:message for="chgWt" style="font-weight: bold;color: red"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Rate"/>
                            </f:facet>
                            <h:outputText value="#{item.rate}" rendered="#{item != invoiceBean.selectedInvoiceItem}"/>
                            <h:inputText  id="rate" size="8"  value="#{item.rate}"  validatorMessage="&nbsp;*" requiredMessage="&nbsp;*" rendered="#{item == invoiceBean.selectedInvoiceItem}" style="text-align: right;">
                                <f:validateDoubleRange minimum="0.09"/>
                                <f:convertNumber currencySymbol="" type="currency"/>
                            </h:inputText>
                            <h:message for="rate" style="font-weight: bold;color: red"/>
                        </p:column>
                        <p:column width="50">
                            <f:facet name="header">
                                <h:outputText value="Amount"/>
                            </f:facet>
                            <h:outputText  value="#{item.rate * item.chargedWeight}">
                                <f:convertNumber currencySymbol="Rs." type="currency"/>
                            </h:outputText>

                        </p:column>
                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="Ref#"/>
                            </f:facet>
                            <h:outputText value="#{item.referenceNumber}" rendered="#{item != invoiceBean.selectedInvoiceItem}"/>
                            <h:inputText size="10" value="#{item.referenceNumber}" rendered="#{item == invoiceBean.selectedInvoiceItem}"/>
                        </p:column>

                        <p:column >
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            
                            <p:commandButton action="#{invoiceBean.deleteRow(item)}" value="Delete"  immediate="true" ajax="false"/>

                        </p:column>
                    </p:dataTable>

                    <table border="0" width="70%">
                        <tr>
                            <td align="left" rowspan="2">
                                <p:commandButton action="#{invoiceBean.newRow}" style="margin-right: 10px;" value="Add Item" update="entryPanel"/>

                            </td>
                            <td align="right">
                                <h:outputLabel value="Total :" for="total" style="font-weight: bold;" />
                            </td>
                            <td align="right" width="90">
                                <h:outputText  id="total" value="#{invoiceBean.selected.totalAmount}" style="font-weight: bold;">
                                    <f:convertNumber currencySymbol="Rs " type="currency"/>
                                </h:outputText>
                            </td>
                        </tr>
                        <tr>

                            <td align="right">
                                <h:outputLabel value="Grand Total :" for="grandTotal" style="font-weight: bold;" />
                            </td>
                            <td align="right" width="90">
                                <h:outputText  id="grandTotal" value="#{invoiceBean.selected.totalAmount + invoiceBean.selected.extraCharge - invoiceBean.selected.discount}" style="font-weight: bold;text-align: right;" >
                                    <f:convertNumber currencySymbol="Rs " type="currency"/>
                                </h:outputText>
                            </td>
                        </tr>
                    </table>
                    <f:facet name="footer">
                        <p:commandButton action="#{invoiceBean.create}" value="Save" update="entryPanel" />
                        <p:commandButton action="pretty:listUsers" value="Cancel" immediate="true"/>
                    </f:facet>
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
